package linker.list;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import linker.window.WindowSaver;

/**
 * 
 * @version linker 0.93
 * @author Jianfeng coxzjkwl@gmail.com
 * 
 */
public class FunctionEdit extends JFrame implements ActionListener {
	// @_@
	private static final long serialVersionUID = 1L;

	private FunctionItem item;

	private JTextField titleField = new JTextField(20);

	private JTextField commandField = new JTextField(20);

	private JButton saveButton = new JButton("Save");

	public FunctionEdit(FunctionItem item) {
		super("Edit " + item.getTitle());
		setName("Edit" + item.getTitle());

		this.item = item;

		Container container = getContentPane();
		container.setLayout(new FlowLayout());

		container.add(new JLabel("Title:"));
		titleField.setText(item.getTitle());
		container.add(titleField);

		container.add(new JLabel("Command:"));
		commandField.setText(item.getCommand());
		container.add(commandField);

		saveButton.addActionListener(this);
		container.add(saveButton);

		setSize(400, 400);
		setLocationRelativeTo(null);
		try {
			WindowSaver.getWindowSaver().loadSettings(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		item.setTitleAndCommand(titleField.getText(), commandField.getText());
	}

}
